package com.zzw.bridge.business.controller;

import com.zzw.bridge.business.dto.AddProjectDTO;
import com.zzw.bridge.business.dto.ZzwPierProjectDTO;
import com.zzw.bridge.business.service.ZzwPierProjectService;
import com.zzw.bridge.business.vo.QueryIdVo;
import com.zzw.bridge.business.vo.ZzwPierProjectVo;
import com.zzw.bridge.common.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 大桥项目控制器
 *
 * @author XiaoJie
 * @date 2025-05-19 10:32:20
 */

@Tag(name = "大桥项目控制器")
@RestController
@RequestMapping("business/project")
@Slf4j
public class ZzwPierProjectController {

    @Resource
    private ZzwPierProjectService projectService;

    @PostMapping("/queryPage")
    @Operation(summary = "分页查询")
    public Result<List<ZzwPierProjectVo>> queryPage (@RequestBody ZzwPierProjectDTO dto, HttpServletRequest request) {
        return Result.ok(projectService.queryPage(dto,request));
    }

    @PostMapping("/queryProjectType")
    @Operation(summary = "获取项目类型")
    public Result<HashMap<Integer, String>> queryProjectType () {
        return Result.ok(projectService.queryProjectType());
    }

    @PostMapping("/queryIdList/{projectType}")
    @Operation(summary = "获取项目ID列表")
    public Result<List<QueryIdVo>> queryIdList (@PathVariable("projectType") Integer projectType) {
        return Result.ok(projectService.queryIdList(projectType));
    }

    @PostMapping("/addProject")
    @Operation(summary = "新增")
    public Result<String> addProject (@RequestBody @Validated AddProjectDTO dto, HttpServletRequest request) {
        return Result.ok(projectService.addProject(dto,request));
    }

    @PostMapping("/removeProject/{id}")
    @Operation(summary = "删除")
    public Result<Integer> removeProject (@PathVariable("id")String id) {
        return Result.ok(projectService.removeProject(id));
    }

    @PostMapping("/editProject")
    @Operation(summary = "编辑")
    public Result<Integer> editProject (@RequestBody ZzwPierProjectDTO dto) {
        return Result.ok(projectService.editProject(dto));
    }

    @PostMapping("/queryTypeList")
    @Operation(summary = "根据projectType获取分组列表")
    public Result<Map<Integer,List<ZzwPierProjectVo>>> queryTypeList (HttpServletRequest request) {
        return Result.ok(projectService.queryTypeList(request));
    }

    @PostMapping("/queryVoById/{id}")
    @Operation(summary = "根据id查vo以及子节点")
    public Result<ZzwPierProjectVo> queryVoById (HttpServletRequest request, @PathVariable("id") String id) {
        return Result.ok(projectService.queryVoById(request,id));
    }

    @PostMapping("/checkEndLevel/{id}")
    @Operation(summary = "判断最末端节点层级(true-该节点末端节点层级小于5允许创建父子节点；false-该节点末端节点层级大于5不允许创建父子节点))")
    public Result<Boolean> checkEndLevel (@PathVariable("id")String id,HttpServletRequest request) {
        return Result.ok(projectService.checkEndLevel(id,request));
    }
}
